e024aacf18c137cdb61b2dcdfe4739a2c620512f,src/scythe_interface/Synthesizer.java,Synthesizer,Synthesize,#String#AbstractTableEnumerator#,29
Before Change
}
//##### Synthesis
config.setMaxDepth(maxDepth);
candidates.addAll(enumerator.enumProgramWithIO(inputs, output, config));
config.setAggrFunctions(new ArrayList<>());
if (maxDepth == 1) {
List<Set<Function<List<Value>, Value>>> aggrFunctionSets =
SynthesizerHelper.getRelatedFunctions(config.getConstValues(), inputs, output);
for (Set<Function<List<Value>, Value>> funcSet : aggrFunctionSets) {
config.setAggrFunctions(funcSet);
EnumConfig tempConfig = config.deepCopy();
if (!containsDesirableCandidate(candidates)) {
// guess constants
Set<NumberVal> guessedNumConstants = SynthesizerHelper.guessExtraConstants(config.getAggrFuns(), inputs);
tempConfig.addConstVals(guessedNumConstants.stream().collect(Collectors.toSet()));
}
candidates.addAll(enumerator.enumProgramWithIO(inputs, output, tempConfig));
//if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
if (containsDesirableCandidate(candidates)) break;
//##### Try decompose tables
if (GlobalConfig.TRY_DECOMPOSITION
&& output.getContent().size() <= GlobalConfig.TRY_DECOMPOSE_ROW_NUM) {
config.setMaxDepth(1);
config.setAggrFunctions(SynthesizerHelper.getRelatedFunctions(config.getConstValues(), inputs, output).get(0));
candidates.addAll(SynthesizerHelper.synthesizeWithDecomposition(inputs, output, config, enumerator));
config.setMaxDepth(1);
}
if (containsDesirableCandidate(candidates)) break;
//##### try synthesis with aggregation functions
config.setAggrFunctions(AggregationNode.getAllAggrFunctions());
candidates.addAll(enumerator.enumProgramWithIO(inputs, output, config));
if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
if (maxDepth == 2) {
if (containsDesirableCandidate(candidates)) break;
List<Set<Function<List<Value>, Value>>> aggreFunctions =
SynthesizerHelper.rankAggrFunctions(config.getConstValues(), inputs, output);
for (Set<Function<List<Value>, Value>> funcSet : aggreFunctions) {
// guess constants
if (!containsDesirableCandidate(candidates)) {
Set<NumberVal> guessedNumConstants = SynthesizerHelper.guessExtraConstants(config.getAggrFuns(), inputs);
config.addConstVals(guessedNumConstants.stream().collect(Collectors.toSet()));
}
config.setAggrFunctions(funcSet);
candidates.addAll(enumerator.enumProgramWithIO(inputs, output, config));
if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
}
if (maxDepth == 2) {
// try synthesizing queries with Exists-clauses
for (Table existsCore : inputs) {
config.setExistsCore(2, Arrays.asList(existsCore));
config.setMaxDepth(0);
candidates.addAll(enumerator.enumProgramWithIO(inputs, output, config));
if (containsDesirableCandidate(candidates)) break;
}
config.setExistsCore(0, new ArrayList<>());
After Change
// Ignore provided aggregation functions
config.setAggrFunctions(new ArrayList<>());
List<TableNode> candidates = new ArrayList<>();
int depth = 0;
while (timeUsed < Synthesizer.TimeOut) {
System.out.println("[[Retry]] Trying to search for depth: " + depth);
if (depth == 2) System.out.println(output);
if (depth == 0) {
//allow using all aggregation functions
config.setAggrFunctions(AggregationNode.getAllAggrFunctions());
}
//##### Synthesis
config.setMaxDepth(depth);
List<TableNode> synthesisResult = enumerator.enumProgramWithIO(inputs, output, config);
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage * 2));
config.setAggrFunctions(new ArrayList<>());
if (depth == 1) {
synthesisResult = new ArrayList<>();
// iterate over all candidate aggregation functions
for (Set<Function<List<Value>, Value>> funcSet
: SynthesizerHelper.getRelatedFunctions(config.getConstValues(), inputs, output)) {
config.setAggrFunctions(funcSet);
EnumConfig tempConfig = config.deepCopy();
if (!containsDesirableCandidate(candidates)) {
// guess constants
Set<NumberVal> guessedNumConstants = SynthesizerHelper.guessExtraConstants(config.getAggrFuns(), inputs);
tempConfig.addConstVals(guessedNumConstants.stream().collect(Collectors.toSet()));
}
synthesisResult.addAll(enumerator.enumProgramWithIO(inputs, output, tempConfig));
//if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage));
if (containsDesirableCandidate(candidates)) break;
//##### Try decompose tables
if (GlobalConfig.TRY_DECOMPOSITION
&& output.getContent().size() <= GlobalConfig.TRY_DECOMPOSE_ROW_NUM) {
config.setMaxDepth(1);
config.setAggrFunctions(SynthesizerHelper.getRelatedFunctions(config.getConstValues(), inputs, output).get(0));
synthesisResult = SynthesizerHelper.synthesizeWithDecomposition(inputs, output, config, enumerator);
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage));
config.setMaxDepth(1);
}
if (containsDesirableCandidate(candidates)) break;
//##### try synthesis with all aggregation functions
config.setAggrFunctions(AggregationNode.getAllAggrFunctions());
synthesisResult = enumerator.enumProgramWithIO(inputs, output, config);
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage));
if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
if (depth == 2) {
if (containsDesirableCandidate(candidates)) break;
List<Set<Function<List<Value>, Value>>> aggreFunctions =
SynthesizerHelper.rankAggrFunctions(config.getConstValues(), inputs, output);
for (Set<Function<List<Value>, Value>> funcSet : aggreFunctions) {
// guess constants
if (!containsDesirableCandidate(candidates)) {
Set<NumberVal> guessedNumConstants = SynthesizerHelper.guessExtraConstants(config.getAggrFuns(), inputs);
config.addConstVals(guessedNumConstants.stream().collect(Collectors.toSet()));
}
config.setAggrFunctions(funcSet);
synthesisResult = enumerator.enumProgramWithIO(inputs, output, config);
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage));
if (containsDesirableCandidate(candidates)) break;
config.setAggrFunctions(new ArrayList<>());
}
//**** try synthesizing queries with Exists-clauses
for (Table existsCore : inputs) {
config.setExistsCore(2, Arrays.asList(existsCore));
config.setMaxDepth(0);
synthesisResult = enumerator.enumProgramWithIO(inputs, output, config);
candidates.addAll(findTopK(synthesisResult, maxCandidateKeptEachStage));
if (containsDesirableCandidate(candidates)) break;
}